package palms.authserver;

import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;

import javax.crypto.spec.SecretKeySpec;

import palms.security.PalmsSecurityManager;



public class AuthLogic {

	private int kasport;
	private int ktgsport;
	
	private String siip;
	
	private HashMap<String,String> userlist;
	
	private SecretKeySpec keyTGS;
	private SecretKeySpec keySI;
	private SecretKeySpec keySL;
	
	
	public AuthLogic(){
		this.userlist = new HashMap<String,String>();
		this.init();
	}

	public void init(){

		//Populate user list
		this.userlist.put("fireman", "inseguro");

		this.setKasport(56421);
		this.setKtgsport(56422);
		
		try {
			
			this.setSiip(InetAddress.getLocalHost().getHostAddress());
			
			//TGS key
			String stk = "oservidortgsrulabueseeomaiordomundo";
			this.setKeyTGS(PalmsSecurityManager.getKeyFromString(stk));
			//SI key
			String sik = "identificacaoidenificacaoidentificacao";
			this.setKeySI(PalmsSecurityManager.getKeyFromString(sik));
			//SL key
			String slk = "locationlocationlocationlocation";
			this.setKeySL(PalmsSecurityManager.getKeyFromString(slk));
			
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	

	public void setKasport(int kasport) {
		this.kasport = kasport;
	}

	public int getKasport() {
		return kasport;
	}

	public void setKtgsport(int ktgsport) {
		this.ktgsport = ktgsport;
	}

	public int getKtgsport() {
		return ktgsport;
	}

	public HashMap<String, String> getUserlist() {
		return userlist;
	}

	public void setUserlist(HashMap<String, String> userlist) {
		this.userlist = userlist;
	}

	public SecretKeySpec getKeyTGS() {
		return keyTGS;
	}

	public void setKeyTGS(SecretKeySpec keyTGS) {
		this.keyTGS = keyTGS;
	}

	public SecretKeySpec getKeySI() {
		return keySI;
	}

	public void setKeySI(SecretKeySpec keySI) {
		this.keySI = keySI;
	}

	public SecretKeySpec getKeySL() {
		return keySL;
	}

	public void setKeySL(SecretKeySpec keySL) {
		this.keySL = keySL;
	}

	public String getSiip() {
		return siip;
	}

	public void setSiip(String siip) {
		this.siip = siip;
	}
	
	

}
